package first.codeTop.tencent;

/**
 * @ClassName LC54
 * @description:
 * @author: 荣燊
 * @create: 2021-10-27 16:27
 **/
public class LC54 {
    // 二叉搜索树的第k大节点
    public static void main(String[] args) {

    }

    public int k;
    public int res;

    // 遍历顺序右孩子-》根节点-》左孩子
    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    public void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(root.right);
        if (--k == 0) {
            res = root.val;
        }
        dfs(root.left);
    }
}
